/**
 * Created by WT-SUN on 2017/5/3.
 */

$(function () {
    dzgTask();
    $('#tabTask').tabs({
        border:false,
        onSelect:function(title,index){
            if (index==0){
                dzgTask();
            }
            if(index==1){
                yzgTask();
            }
            if(index==2){
                ysTask();
            }
            if (index==3){
                yysTask();
            }
        }
    });
    $('#btn_clear').on("click", function () {
        $('#queryForm').form('reset');
    });
});
function dzgTask() {
    $('#taskTbzg').datagrid({
        rownumbers: true,//显示行号
        striped: true,
        fit: true,
        singleSelect: true,
        sortOrder: true,
        fitColumns: true,
        pagination: true,
        toolbar: '#toolbar',
        url: ROOT_PATH + '/task/taskTable.shtml',
        queryParams:{
            sort:'addTime',
            order:'desc',
            state:'1',
            zgTime:'1',
            flag:'zg'
        },
        columns: [[
            {
                field: 'id',
                checkbox: true
            },
            {
                field: 'taskId', hidden:true, title: '业务Id', hidden:true,width: 20
            },
            {field: 'aa', title: '操作', width: 50, sortable: true,formatter: function (value, row, index) {
                return "<a href='javascript:void(0)' class='easyui-linkbutton text-primary' plain='true'   onclick='zgTaskFun(\""+row.id+"\",\""+row.state+"\");'>整改</a>";
            }},
            {field: 'taskName', title: '任务名称', width: 120,formatter: function (value, row, index) {
                return "<a href='javascript:void(0)' class='easyui-linkbutton text-primary' plain='true'   onclick='infoTaskData(\""+row.id+"\");'>"+row.taskName+"</a>";
            }},
            {field: 'taskDescribe', title: '任务描述', width: 80},
            {field: 'taskSource', title: '任务来源', width: 80},
            {field: 'addTime', title: '任务提交时间', width: 100},
            {field: 'requireTime', title: '计划完成日期', width: 100},
            {field: 'state', title: '状态', width: 100,formatter: function (value, row, index) {
                //return typeof (row.state)=='undefined'?'未下发':(row.state=='1'?'整改中':'已验收');
                return typeof (row.state)=='undefined'?'<span class="color-important text-white" style="padding: 3px;border-radius:5px;">未下发</span>':(row.state=='1'?'<span class="color-info text-white" style="padding: 3px;border-radius:5px;">整改中</span>':'<span class="color-success text-white" style="padding: 3px;border-radius:5px;">已验收</span>');
            }},
        ]],
    });
}
function yysTask() {
    $('#taskTbyys').datagrid({
        rownumbers: true,//显示行号
        striped: true,
        fit: true,
        singleSelect: true,
        sortOrder: true,
        fitColumns: true,
        pagination: true,
        toolbar: '#toolbar',
        url: ROOT_PATH + '/task/taskTable.shtml',
        queryParams:{
            sort:'addTime',
            order:'desc',
            ysTime:'0',
            flag:'ys'
        },
        columns: [[
            {
                field: 'id',
                checkbox: true
            },
            {
                field: 'taskId', hidden:true, title: '业务Id', hidden:true,width: 20
            },
            /*{field: 'aa', title: '操作', width: 50, sortable: true,formatter: function (value, row, index) {
                return "<a href='javascript:void(0)' style='color:#0b6bc2;'  onclick='ysTaskFun(\""+row.id+"\",\""+row.state+"\");'>验收</a>";
            }},*/
            {field: 'taskName', title: '任务名称', width: 120,formatter: function (value, row, index) {
                return "<a href='javascript:void(0)' style='color:#0b6bc2;'  onclick='infoTaskData(\""+row.id+"\");'>"+row.taskName+"</a>";
            }},
            {field: 'taskDescribe', title: '任务描述', width: 80},
            {field: 'taskSource', title: '任务来源', width: 80},
            {field: 'addTime', title: '任务提交时间', width: 100},
            {field: 'requireTime', title: '计划完成日期', width: 100},
            {field: 'state', title: '状态', width: 100,formatter: function (value, row, index) {
                return typeof (row.state)=='undefined'?'<span class="color-important text-white" style="padding: 3px;border-radius:5px;">未下发</span>':(row.state=='1'?'<span class="color-info text-white" style="padding: 3px;border-radius:5px;">整改中</span>':'<span class="color-success text-white" style="padding: 3px;border-radius:5px;">已验收</span>');
            }},
        ]],
    });
}
function ysTask() {
    $('#taskTbys').datagrid({
        rownumbers: true,//显示行号
        striped: true,
        fit: true,
        singleSelect: true,
        sortOrder: true,
        fitColumns: true,
        pagination: true,
        toolbar: '#toolbar',
        url: ROOT_PATH + '/task/taskTable.shtml',
        queryParams:{
            sort:'addTime',
            order:'desc',
            zgTime:'0',
            ysTime:'1',
            flag:'ys'
        },
        columns: [[
            {
                field: 'id',
                checkbox: true
            },
            {
                field: 'taskId', hidden:true, title: '业务Id', hidden:true,width: 20
            },
            {field: 'aa', title: '操作', width: 50, sortable: true,formatter: function (value, row, index) {
                return "<a href='javascript:void(0)' style='color:#0b6bc2;'  onclick='ysTaskFun(\""+row.id+"\",\""+row.state+"\");'>验收</a>";
            }},
            {field: 'taskName', title: '任务名称', width: 120,formatter: function (value, row, index) {
                return "<a href='javascript:void(0)' style='color:#0b6bc2;'  onclick='infoTaskData(\""+row.id+"\");'>"+row.taskName+"</a>";
            }},
            {field: 'taskDescribe', title: '任务描述', width: 80},
            {field: 'taskSource', title: '任务来源', width: 80},
            {field: 'addTime', title: '任务提交时间', width: 100},
            {field: 'requireTime', title: '计划完成日期', width: 100},
            {field: 'state', title: '状态', width: 100,formatter: function (value, row, index) {
                return typeof (row.state)=='undefined'?'<span class="color-important text-white" style="padding: 3px;border-radius:5px;">未下发</span>':(row.state=='1'?'<span class="color-info text-white" style="padding: 3px;border-radius:5px;">整改中</span>':'<span class="color-success text-white" style="padding: 3px;border-radius:5px;">已验收</span>');
            }},
        ]],
    });
}
function yzgTask() {
    $('#taskTbyzg').datagrid({
        rownumbers: true,//显示行号
        striped: true,
        fit: true,
        singleSelect: true,
        sortOrder: true,
        fitColumns: true,
        pagination: true,
        toolbar: '#toolbar',
        url: ROOT_PATH + '/task/taskTable.shtml',
        queryParams:{
            sort:'addTime',
            order:'desc',
            zgTime:'0',
            flag:'zg'
        },
        columns: [[
            {
                field: 'id',
                checkbox: true
            },
            {
                field: 'taskId', hidden:true, title: '业务Id', hidden:true,width: 20
            },
            {field: 'aa', title: '操作', width: 50, sortable: true,formatter: function (value, row, index) {
                return "<a href='javascript:void(0)' style='color:#0b6bc2;'  onclick='zgTaskFun(\""+row.id+"\",\""+row.state+"\");'>整改</a>";
            }},
            {field: 'taskName', title: '任务名称', width: 120,formatter: function (value, row, index) {
                return "<a href='javascript:void(0)' style='color:#0b6bc2;'  onclick='infoTaskData(\""+row.id+"\");'>"+row.taskName+"</a>";
            }},
            {field: 'taskDescribe', title: '任务描述', width: 80},
            {field: 'taskSource', title: '任务来源', width: 80},
            {field: 'addTime', title: '任务提交时间', width: 100},
            {field: 'requireTime', title: '计划完成日期', width: 100},
            {field: 'state', title: '状态', width: 100,formatter: function (value, row, index) {
                return typeof (row.state)=='undefined'?'<span class="color-important text-white" style="padding: 3px;border-radius:5px;">未下发</span>':(row.state=='1'?'<span class="color-info text-white" style="padding: 3px;border-radius:5px;">整改中</span>':'<span class="color-success text-white" style="padding: 3px;border-radius:5px;">已验收</span>');
            }},
        ]],
    });
}
function infoTaskData(id) {
    var title = '任务详情';
    var content = ROOT_PATH + '/task/info.shtml?resourceId=' + $.getQueryParam('resourceId')+'&id=' + id+'&type=info';
    parent.layer.open({
        type: 2,
        resize: false,
        title: title,
        area: ['1150px', '60%'],
        content: content
    });
}
function reLoadData() {
    var tab = $('#tabTask').tabs('getSelected');
    var index = $('#tabTask').tabs('getTabIndex',tab);
    var queryParams = $('#queryForm').serializeJson();
    queryParams["sort"] = 'addTime';
    queryParams["order"] = 'desc';
    var tbId="";
    if(index==0){
        tbId='#taskTbzg';
        queryParams["zgTime"] = '1';
        queryParams["state"] = '1';
        queryParams["flag"] = 'zg';
    }else if(index==1){
        tbId='#taskTbyzg';
        queryParams["zgTime"] = '0';
        queryParams["flag"] = 'zg';
    }else if(index==2){
        tbId='#taskTbys';
        queryParams["zgTime"] = '0';
        queryParams["ysTime"] = '1';
        queryParams["flag"] = 'ys';
    }else {
        tbId='#taskTbyys';
        queryParams["ysTime"] = '0';
        queryParams["flag"] = 'ys';
    }
    $(tbId).datagrid('clearSelections');
    $(tbId).datagrid('options').queryParams = queryParams;
    $(tbId).datagrid('reload', ROOT_PATH + '/task/taskTable.shtml');
}

/**
 * 打开弹框
 * @param title
 * @param content
 */
function openLayers(title, content) {
    parent.layer.open({
        type: 2,
        resize: false,
        title: title,
        area: ['700px', '55%'],
        content: content
    });
}
/**
 * 编辑
 */
function zgTaskFun(id,state) {
    if (state=='0'){
        layer.alert("该任务已验收！");
        return;
    }
    var title = '任务整改';
    var content = ROOT_PATH + '/task/info.shtml?resourceId=' + $.getQueryParam('resourceId')+'&id=' + id+'&type=zg';

    parent.layer.open({
        type: 2,
        resize: false,
        title: title,
        area: ['700px', '55%'],
        content: content
    });
    //openLayers(title, content);
}
function ysTaskFun(id,state) {
    var title = '任务验收';
    var content = ROOT_PATH + '/task/info.shtml?resourceId=' + $.getQueryParam('resourceId')+'&id=' + id+'&type=ys';
    parent.layer.open({
        type: 2,
        resize: false,
        title: title,
        area: ['700px', '60%'],
        content: content
    });
}


